import request from '@/utils/request'

export function getRoleListAPI(params) {
    return request({
      url: '/park/sys/role',
      params
    })
  }

  export function getTreeListAPI() {
    return request({
      url: '/park/sys/permision/all/tree'
    })
  }

  export function getRoleDetailAPI(roleId) {
    return request({
      url: `/park/sys/role/${roleId}`
    })
  }

  export function getRoleUserAPI(roleId) {
    return request({
      url: `/park/sys/roleUser/${roleId}`
    })
  }

  export function addDisabled(treeList) {
    treeList.forEach(item => {
      item.disabled = true
      // 递归处理
      if (item.children && item.children.length > 0) {
        addDisabled(item.children)
      }
    })
  }

  export function createRoleUserAPI(data) {
    return request({
      url: `/park/sys/role`,
      method: 'POST',
      data
    })
  }

  export function updateRoleAPI(data) {
    return request({
      url: `/park/sys/role`,
      method: 'PUT',
      data
    })
  }

  export function delRoleUserAPI(roleId) {
    return request({
      url: `/park/sys/role/${roleId}`,
      method: 'DELETE'
    })
  }